package com.wynn.utils;

import java.io.File;

public class FilesUtils {

    public static void deleteByName(String path,String fileName){

        File files = new File(path);
        if(!files.exists()){
            return;
        }
        File[] childFiles = files.listFiles();
        int length = childFiles.length;
        for (int i = 0; i < length; i++) {
            File file = childFiles[i];
            //文件名相等
            String existName = file.getName().split("\\.")[0];
            if (existName.equals(fileName)){
                file.delete();
                return;
            }

        }
    }

    public static String findFileByName(String path,String fileName){
        File files = new File(path);
        if(!files.exists()){
            return "";
        }
        File[] childFiles = files.listFiles();
        int length = childFiles.length;
        for (int i = 0; i < length; i++) {
            File file = childFiles[i];
            String existName = file.getName().split("\\.")[0];
            if (existName.equals(fileName)){
                return file.getName();
            }

        }
        return "";
    }

}
